var personData = [];
var carData = [];
window.personCarIsInit = false;

function setPersonCarstatus() {
    window.personCarIsInit = false;
}

/**
 * 人员
 * @param obj
 */
var clearMaker;//聚合集
var personDatas;
function onClickPerson(obj) {
    var mapArr = [];
    if (window.personCarIsInit === false) {
        map.clearOverlays();
        window.personCarIsInit = true;
    }
    if (obj.checked) {
        var carData = [];
        $.ajax({
            url: baseUrl + "dlxy/main/internetofthings/getpersonnelandvehicle?PatrolEquipmentType=人员",
            type: "get",
            dataType: "json",
            success: function (data) {
                personDatas = data;
                map.centerAndZoom(new BMap.Point(data[0].lng, data[0].lat), 15);
                for (let n = 0; n < data.length; n++) {
                    var point = new BMap.Point(data[n].lng, data[n].lat);
                    var myIcon = new BMap.Icon("img/应急人_u555.svg", new BMap.Size(24, 24));


                    var marker = new BMap.Marker(point, {
                        icon: myIcon
                    }); // 创建标注
                    mapArr.push(marker)//聚合开始
                    map.addOverlay(marker); // 将标注添加到地图中
                    personData.push(marker);

                }
                //最简单的用法，生成一个marker数组，然后调用markerClusterer类即可。
                var markerClusterer = new BMapLib.MarkerClusterer(map, {markers: mapArr});
                clearMaker = markerClusterer;
                //聚合结束

            }
        });
        setPersonCarstatus();
    } else {
        for (var i = 0; i < personData.length - 1; i++) {

            map.removeOverlay(personData[i]);
            clearMaker.clearMarkers(mapArr);//清除聚合
        }
    }

}


/**
 *车辆
 * @param obj
 */
function onClickCar(obj) {
    if (obj.checked) {
        $.ajax({
            url: baseUrl + "dlxy/main/internetofthings/getpersonnelandvehicle?PatrolEquipmentType=车辆",
            type: "get",
            dataType: "json",
            success: function (data) {
                map.centerAndZoom(new BMap.Point(data[0].lng, data[0].lat), 15);
                for (let n = 0; n < data.length; n++) {
                    var point = new BMap.Point(data[n].lng, data[n].lat);
                    var myIcon = new BMap.Icon("img/应急车_u558.svg", new BMap.Size(24, 24));
                    var marker = new BMap.Marker(point, {
                        icon: myIcon
                    }); // 创建标注
                    // marker.addEventListener("click", ry_point.bind(this,data[n]));
                    map.addOverlay(marker); // 将标注添加到地图中
                    carData.push(marker);
                }
            }
        });


    } else {
        for (var i = 0; i < carData.length - 1; i++) {
            map.removeOverlay(carData[i]);
        }
    }

}

/**
 * 人员车辆input框去勾选
 */
function clearCheckBox() {

    if($('#personZn')[0].checked == true && personDatas.length>0){
        clearMaker.clearMarkers();
        $('#personZn')[0].checked = false;
        $('#carZn')[0].checked = false;
    }else{
        $('#personZn')[0].checked = false;
        $('#carZn')[0].checked = false;
    }


}



